<%--
  Created by IntelliJ IDEA.
  User: 王志斌
  Date: 2019/2/1
  Time: 16:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    String static_path = path + "/static/alpha";
    String x_admin_path = path + "/static/X-admin-2.3";
%>
<html>
<head>
    <title>部门管理</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">

    <!-- X-admin -->
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <script type="text/javascript" src="<%=x_admin_path%>/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" href="<%=x_admin_path%>/css/font.css">
    <link rel="stylesheet" href="<%=x_admin_path%>/css/xadmin.css">
    <script type="text/javascript" src="<%=x_admin_path%>/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=x_admin_path%>/js/xadmin.js"></script>
</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
    <!-- 文件头 -->
    <jsp:include page="/manage/inc/head"></jsp:include>

    <!-- 侧边栏 -->
    <jsp:include page="/manage/inc/sidebar"></jsp:include>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1>岗位管理</h1>
                    </div>
                </div>
            </div><!-- /.container-fluid -->
        </section>

        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-12">
                        <!-- Main content -->
                        <div class="invoice p-3 mb-3">

                            <div class="layui-row">
                                <div class="layui-form layui-col-md12 x-so" style="margin-left:130px; margin-top:4px; position:absolute;">
                                    <div class="layui-input-inline">
                                        <select class="valid" lay-search lay-filter="postTypeSelect">
                                            <option value="">岗位类别</option>
                                            <c:forEach items="${requestScope.postTypeList}" var="list">
                                                <c:if test="${!empty list.postTypeList}">
                                                    <optgroup label="${list.name}">
                                                        <c:forEach items="${list.postTypeList}" var="postList">
                                                            <option value="${postList.id}">${postList.name}</option>
                                                        </c:forEach>
                                                    </optgroup>
                                                </c:if>
                                            </c:forEach>

                                            <optgroup label="其他岗位">
                                                <c:forEach items="${requestScope.postTypeList}" var="list">
                                                    <c:if test="${empty list.postTypeList}">
                                                        <option value="${list.id}">${list.name}</option>
                                                    </c:if>
                                                </c:forEach>
                                            </optgroup>

                                            <optgroup label="一级类别">
                                                <c:forEach items="${requestScope.postTypeOne}" var="list">
                                                    <option value="${list.id}"
                                                            <c:if test="${requestScope.postInfo.postTypeId.id eq list.id}">
                                                                selected="selected"
                                                            </c:if>
                                                    >${list.name}</option>
                                                </c:forEach>
                                            </optgroup>

                                        </select>
                                    </div>
                                    <div class="layui-inline">
                                        <select class="valid" lay-search lay-filter="departSelect">
                                            <option value="">部门名称</option>
                                            <c:forEach items="${requestScope.getAllDepartmentList}" var="list">
                                                <option value="${list.id}">${list.departmentName}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <xblock style="background-color:white;">
                                    <button class="layui-btn" onclick="insertPost()"><i class="layui-icon"></i>新增岗位</button>
                                    <span class="x-right" style="position:absolute; margin-left:60%;">
                                    <button class="layui-btn" onclick="x_admin_show('岗位类别管理','<%=path%>/manage/department/post_management/postType')" style="background-color:white; color:black;">岗位类别管理</button>
                                    <%--<button class="layui-btn" onclick="x_admin_show('添加用户','./order-add.html')" style="background-color:white; color:black;">岗位职级管理</button>--%>
                                </span>
                                    <span class="x-right" style="line-height:40px">共有数据：88 条</span>
                                </xblock>
                                <!-- Table row -->
                                <div class="row">
                                    <div class="col-12 table-responsive" id="infoDiv">
                                        <table class="table table-striped">
                                            <thead>
                                            <tr>
                                                <th>岗位名称</th>
                                                <th>部门名称</th>
                                                <th>类别</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <c:forEach items="${requestScope.postList}" var="list">
                                                <tr>
                                                    <td>${list.postType}</td>
                                                    <td>${list.department.departmentName}</td>
                                                    <td>${list.postTypeId.name}</td>
                                                    <td class="td-manage">
                                                        <a title="编辑" onclick="updatePost(${list.id})" href="javascript:;">
                                                            <i class="layui-icon"></i>
                                                        </a>
                                                        <a title="删除" onclick="member_del(this,${list.id})" href="javascript:;">
                                                            <i class="layui-icon"></i>
                                                        </a>
                                                    </td>
                                                </tr>
                                            </c:forEach>
                                            </tbody>
                                        </table>
                                    </div>
                                    <!-- /.col -->
                                    <div id="page" style="margin-left:30%;"></div>
                                </div>
                            </div>
                            <!-- /.invoice -->
                        </div><!-- /.col -->
                    </div><!-- /.row -->
                </div><!-- /.container-fluid -->
                <!-- /.content -->
            </div>

            <!-- 底部包含 -->
            <jsp:include page="/manage/inc/foot"></jsp:include>

    </div>
    <!-- AdminLTE App -->
    <script src="<%=static_path%>/dist/js/adminlte.min.js"></script>

    <script>

        layui.use(['layer', 'form', 'element'], function(){
            var layer = layui.layer
                ,form = layui.form
                ,element = layui.element

            //根据岗位类别搜索
            form.on('select(postTypeSelect)',function (data) {
                if(data.value != "")
                {
                    $.ajax({
                        url:"<%=path%>/manage/department/post_management/ajaxSuccessList",
                        type:"post",
                        data:{postTypeId:data.value},
                        success:function (flag) {
                            $("#infoDiv").html(flag);
                        }
                    });
                }
            });

            //根据部门搜索
            form.on('select(departSelect)', function (data) {
                if(data.value != "")
                {
                    $.ajax({
                        url:"<%=path%>/manage/department/post_management/ajaxSuccessDepart",
                        type:"post",
                        data:{departId:data.value},
                        success:function (flag) {
                            $("#infoDiv").html(flag);
                        }
                    });
                }
            });


            //layui调用分页
            layui.use('laypage', function(){
                var laypage = layui.laypage;

                //执行一个laypage实例
                laypage.render({
                    elem: 'page',
                    count: ${requestScope.dataCount},
                    limit:${requestScope.config.value},
                    jump: function(obj, first){

                        var pageNo = obj.curr;
                        var pageSize = obj.limit;

                        $.ajax({
                            url:"<%=path%>/manage/department/post_management/ajaxSuccessPage",
                            type:"post",
                            data:{pageNo:pageNo,pageSize:pageSize},
                            success:function (flag) {
                                $("#infoDiv").html(flag);
                            }
                        });

                    }
                });
            });


        });





        /*用户-删除*/
        function member_del(obj,id){
            layer.confirm('确认要删除吗？',function(index){

                $.ajax({
                    url:"<%=path%>/manage/department/post_management/delPost",
                    type:"post",
                    data:{postId:id},
                });


                //发异步删除数据
                $(obj).parents("tr").remove();
                layer.msg('已删除!',{icon:1,time:1000});
            });
        }

        /**新增岗位*/
        function insertPost() {
            //iframe层
            parent.layer.open({
                type: 2,
                title: '编辑类别',
                shadeClose: false, //点击遮罩关闭
                anim: 2,
                shade: 0.8,
                area: ['40%', '50%'],
                maxmin: true,
                closeBtn: 1,
                content: ['<%=path%>/manage/department/post_management/insert?type=1', 'yes'], //iframe的url，yes是否有滚动条
                //yes: function (index, layero) {
                //    alert(index);
                //    alert(layero);
                //},
                end: function () {
                    location.reload();
                }

            });
        }

        /**岗位编辑*/
        function updatePost(id) {
            //iframe层
            parent.layer.open({
                type: 2,
                title: '编辑类别',
                shadeClose: false, //点击遮罩关闭
                anim: 2,
                shade: 0.8,
                area: ['40%', '50%'],
                maxmin: true,
                closeBtn: 1,
                content: ['<%=path%>/manage/department/post_management/updatePost?postId='+id, 'yes'], //iframe的url，yes是否有滚动条
                //yes: function (index, layero) {
                //    alert(index);
                //    alert(layero);
                //},
                end: function () {
                    location.reload();
                }

            });
        }


    </script>
</body>
</html>

